package cn.iocoder.yudao.module.biz.controller.admin.licenceSafeMeasures;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.licenceSafeMeasures.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.licenceSafeMeasures.BizLicenceSafeMeasuresDO;
import cn.iocoder.yudao.module.biz.convert.licenceSafeMeasures.BizLicenceSafeMeasuresConvert;
import cn.iocoder.yudao.module.biz.service.licenceSafeMeasures.BizLicenceSafeMeasuresService;

@Api(tags = "管理后台 - 危险作业票安全措施")
@RestController
@RequestMapping("/biz/licence-safe-measures")
@Validated
public class BizLicenceSafeMeasuresController {

    @Resource
    private BizLicenceSafeMeasuresService licenceSafeMeasuresService;

    @PostMapping("/create")
    @ApiOperation("创建危险作业票安全措施")
    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures:create')")
    public CommonResult<String> createLicenceSafeMeasures(@Valid @RequestBody BizLicenceSafeMeasuresCreateReqVO createReqVO) {
        return success(licenceSafeMeasuresService.createLicenceSafeMeasures(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新危险作业票安全措施")
    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures:update')")
    public CommonResult<Boolean> updateLicenceSafeMeasures(@Valid @RequestBody BizLicenceSafeMeasuresUpdateReqVO updateReqVO) {
        licenceSafeMeasuresService.updateLicenceSafeMeasures(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除危险作业票安全措施")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures:delete')")
    public CommonResult<Boolean> deleteLicenceSafeMeasures(@RequestParam("id") String id) {
        licenceSafeMeasuresService.deleteLicenceSafeMeasures(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得危险作业票安全措施")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures:query')")
    public CommonResult<BizLicenceSafeMeasuresRespVO> getLicenceSafeMeasures(@RequestParam("id") String id) {
        BizLicenceSafeMeasuresDO licenceSafeMeasures = licenceSafeMeasuresService.getLicenceSafeMeasures(id);
        return success(BizLicenceSafeMeasuresConvert.INSTANCE.convert(licenceSafeMeasures));
    }

    @GetMapping("/list")
    @ApiOperation("获得危险作业票安全措施列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures:query')")
    public CommonResult<List<BizLicenceSafeMeasuresRespVO>> getLicenceSafeMeasuresList(@RequestParam("ids") Collection<String> ids) {
        List<BizLicenceSafeMeasuresDO> list = licenceSafeMeasuresService.getLicenceSafeMeasuresList(ids);
        return success(BizLicenceSafeMeasuresConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得危险作业票安全措施分页")
    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures:query')")
    public CommonResult<PageResult<BizLicenceSafeMeasuresRespVO>> getLicenceSafeMeasuresPage(@Valid BizLicenceSafeMeasuresPageReqVO pageVO) {
        PageResult<BizLicenceSafeMeasuresDO> pageResult = licenceSafeMeasuresService.getLicenceSafeMeasuresPage(pageVO);
        return success(BizLicenceSafeMeasuresConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出危险作业票安全措施 Excel")
    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures:export')")
    @OperateLog(type = EXPORT)
    public void exportLicenceSafeMeasuresExcel(@Valid BizLicenceSafeMeasuresExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizLicenceSafeMeasuresDO> list = licenceSafeMeasuresService.getLicenceSafeMeasuresList(exportReqVO);
        // 导出 Excel
        List<BizLicenceSafeMeasuresExcelVO> datas = BizLicenceSafeMeasuresConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "危险作业票安全措施.xls", "数据", BizLicenceSafeMeasuresExcelVO.class, datas);
    }

}
